import React, { useState, useEffect, useRef } from 'react';
import styles from './index.less';
import { FormattedMessage, setLocale } from 'umi-plugin-react/locale';
import { connect } from 'dva';
import { GlobalState, UmiComponentProps } from '@/common/type';
import { Redirect } from 'umi';
import usePropsCheck from '@/hooks/propsCheck';

type PageProps = UmiComponentProps;

const BasicLayout: React.FC<PageProps> = props => {
  const { children, route, location } = props;

  useEffect(() => {
    console.log('didAmount');
  });

  const changesObj = usePropsCheck(props);

  if (checkPageRouter(route, location)) {
    return (
      <React.Fragment>
        <div className={styles.appWrap}>{children}</div>
      </React.Fragment>
    );
  } else {
    return <Redirect to="/404" />;
  }
};

export default BasicLayout;

function checkPageRouter(route: { routes: any[] }, location: any): boolean {
  return route.routes.map(r => r.path).some(m => m === location.pathname);
}
